package test {
	import com.xskip.display.StageLink;
	import sandy.util.DistortImage;

	import org.aswing.utils.HashMap;

	import flash.display.Bitmap;
	import flash.display.Sprite;	

	/**
	 * @author JamesXie
	 * @version 1.0
	 * @date Jan 21, 2011
	 * @name TestBianXing 测试变形类
	 */
	public class TestBianXing extends Sprite {
		private var _hmImage : HashMap;

		public function TestBianXing() : void {
			init();
			run();
		}

		private function init() : void {
		}

		private function run() : void {
			var fHashMap : HashMap = new HashMap();
			fHashMap.put("key01", "asset/floor/BM_SHDWFANG_KCHNFLR_01.jpg");
			fHashMap.put("key02", "asset/floor/BM_ULDAMAN_DIRTFLR01.jpg");
			fHashMap.put("key03", "asset/floor/BM_ULDAMAN_SANDFLR01.jpg");
			fHashMap.put("key04", "asset/floor/JLO_UDERCITY_GROUND_01.jpg");
			fHashMap.put("key05", "asset/floor/JLO_UNDEADZIGG_SLIMEFLOOR.jpg");
			fHashMap.put("key06", "asset/other/pixel_house.png");
			
			var fTestLoadList : TestLoadList; 
			fTestLoadList = new TestLoadList(fHashMap, loadCompleteHandler);
		}

		private function loadCompleteHandler(pHashMap : HashMap) : void {
			trace("[DEBUG] [TestBianXing] loadCompleteHandler");
			trace("pHashMap " + pHashMap);
			_hmImage = pHashMap.clone();
			
			//testBianXing();
			
			//需要那个素材
			var fAssetStr:String = "key03";
			
			/*testTiles(fAssetStr, 0, 0);
			testTiles(fAssetStr, 128, 64);
			testTiles(fAssetStr, 256, 128);
			testTiles(fAssetStr, 384, 192);
			testTiles(fAssetStr, 512, 256);
			
			testTiles(fAssetStr, -128, 64);
			testTiles(fAssetStr, 0, 128);
			testTiles(fAssetStr, 128, 192);
			testTiles(fAssetStr, 256, 256);
			testTiles(fAssetStr, 384, 320);*/
			
			//全局移动
			var allX:Number = 200;
			var allY:Number = -300;
			
			for (var i:int = 0; i < 10; i++ ) {
				for (var j:int = 0; j < 10; j++ ) {
					testTiles(fAssetStr, (i*128)-(128*j)+allX, i*64+(64*j)+allY);
				}
			}
		}

		private function testBianXing() : void {
			
			var fBitmap : Bitmap = _hmImage.getValue("key03");
			
			trace(fBitmap.width);
			trace(fBitmap.height);
			
			//addChild(_hmImage.getValue("key01"));

			var fDistortImage : DistortImage = new DistortImage();
			
			var fsp : Sprite = new Sprite();

			StageLink.STAGE.addChild(fsp);
			
			fDistortImage.target = fBitmap.bitmapData;
			fDistortImage.initialize(1, 1);
			fDistortImage.container = fsp;
			//fDistortImage.setTransform(0, 0, 200, 0, 300, 249, 0, 149);
			
			fDistortImage.setTransform(128, 64, 256, 128, 128, 192, 0, 128);
			
			fDistortImage.render();
		}
		
		private function testTiles(assetKey:String,x:Number,y:Number) :void{
			var fBitmap : Bitmap = _hmImage.getValue(assetKey);
			
			trace(fBitmap.width);
			trace(fBitmap.height);
			
			//addChild(_hmImage.getValue("key01"));

			var fDistortImage : DistortImage = new DistortImage();
			
			var fsp : Sprite = new Sprite();
			fsp.x = x;
			fsp.y = y-64;

			StageLink.STAGE.addChild(fsp);
			
			fDistortImage.target = fBitmap.bitmapData;
			fDistortImage.initialize(2, 2);
			fDistortImage.container = fsp;
			//fDistortImage.setTransform(0, 0, 200, 0, 300, 249, 0, 149);
			
			fDistortImage.setTransform(128, 64, 256, 128, 128, 192, 0, 128);
			
			fDistortImage.render();
		}

		private function test() : void {
			/*import sandy.util.DistortImage;
			var fDistortImage : DistortImage = new DistortImage();
			var fsp : Sprite = new Sprite();
			var fBitmap : Bitmap = new Bitmap();
			fBitmap.bitmapData = new myBmp(100, 100);
			addChild(fsp);
			fDistortImage.target = fBitmap.bitmapData;
			fDistortImage.initialize(2, 2);
			fDistortImage.container = fsp;
			fDistortImage.setTransform(0, 0, 200, 0, 300, 249, 0, 149);
			fDistortImage.render();*/
		}
	}
}